import {defineStore} from 'pinia'

export const useStore = defineStore('store', {
    state: () => {//定义需要共享的变量
        return {
            author: '小明', //定义全局变量
            user: {        //定义一个对象
                name: 'xiaoming',
                sex: 'F'
            },
            token: '',
            currentCourse: {
                // courseId: '',
                // courseSubTpye:'',
                // courseType:'',
                // description:'',
                // discountPrice:0,
                // endDate:'',
                // price:'',
                // startDate:'',
                // imageUrl:'',
                // name:'',
                // profileText:'',
                // profileUrl:'',
                // teacherId: '',
                // title: '',
            },
            currentAddress: {},
            material: {},
            openVideoCourseInfo: {},

        }
    },
    //定义方法  设置state中的值 set方法
    actions: {
        setAuthor(author) { //定义函数 修饰变量的值
            this.author = author;
        },
        setUser(user) {   // 定义设置的函数
            this.user = user;
        },
        setToken(token) {
            this.token = token;
        },
        setCurrentCourse(course) {
            this.currentCourse = course;
        },
        setCurrentAddress(address) {
            this.currentAddress = address;
        },
        setMaterial(material) {
            this.material = material;
        },
        setOpenVideoCourseInfo(video) {
            this.openVideoCourseInfo = video;
        },
    }
    , persist: {
        enabled: true // true 表示开启持久化保存
    }
})